﻿@{
    ViewBag.Title = "用户注册";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<script>
    $(function () {
        $("#saveUser").click(function () {
            if ($("input[name='UserName']").val().length < 6) {

                $("#infouser").addClass("error");

            }else{
                $.post("/User/CheckUser", { UserName: $("input[name='UserName']").val() }, function (data) {
                    if (data.Result) {
                        if ($("input[name='Password']").val().length < 6)  {                        
                            $("#infopassword").html("密码不能少于6个字符");
                            $("#infopassword").addClass("error");
                        }
                        else if ($("input[name='Password']").val() != $("input[name='EnterPassword']").val()) {
                            $("#infoenterpassword").html("密码输入不一致");
                            $("#infoenterpassword").addClass("error");
                        }
                        else {
                            alert(valid_email($("input[name='Email']").val()));
                            if (valid_email($("input[name='Email']").val())) {
                                $.post("/User/CheckEmail", { Email: $("input[name='Email']").val() }, function (dataresult) {
                                    if (dataresult.Result) {
                                        $.post("/User/RegUser", { UserName: $("input[name='UserName']").val(), Password: $("input[name='Password']").val(), EnterPassword: $("input[name='EnterPassword']").val(), Email: $("input[name='Email']").val() }, function (dr) {
                                            if (dr.Result == true) {
                                                location.href = "/User/Home";
                                            }
                                        })
                                    }
                                    else {
                                        $("#infoemail").html(dataresult.Messages);
                                        $("#infoemail").addClass("error");
                                    }
                                })
                            }
                            else {
                                $("#infoemail").html("请输入一个正确的EMAIL");
                                $("#infoemail").addClass("error");
                            }
                        }


                    }
                    else {
                        $("#infouser").html(data.Messages);
                        $("#infouser").addClass("error");
                    }
                })
            }
            })

    })
   
    //$.post("/User/RegUser", {}, function (data) {

    //})
</script>
<div class="border" style="margin:5px; margin-bottom:20px;">
<div style="margin:20px; color:#a2d312; font-size:30px;"> 注册 </div>
<div class="poitline"></div>
<div class="reg_left">用户名：</div><div class="reg_mid"><input id="UserName" name="UserName" type="text" /></div><div id="infouser" class="reg_right" >*用户名6~20个字符</div>
<div class="clear"></div>
<div class="reg_left">密码：</div><div class="reg_mid"><input id="Password" name="Password"  type="password" /></div><div id="infopassword" class="reg_right" >*密码最少6个字符</div>
<div class="clear"></div>
<div class="reg_left">重复密码：</div><div class="reg_mid"><input id="EnterPassword" name="EnterPassword" type="password" /></div><div id="infoenterpassword" class="reg_right" >*密码最少6个字符</div>
<div class="clear"></div>
<div class="reg_left">邮箱：</div><div class="reg_mid"><input id="Email" type="text" name="Email" /></div><div id="infoemail" class="reg_right" >*</div>
<div class="clear"></div>
<div class="reg_left"><input id="Radio1" type="radio" checked />同意服务条款</div><div class="reg_mid"></div> <div class="reg_right" > </div>
<div class="clear"></div>
<div class="reg_left"></div><div class="reg_mid">
    <input id="saveUser" type="button" value="注册" /></div> <div class="reg_right" > </div>
<div class="clear"></div>

    
</div>